<?php
/**
 * 服务抽象类
 * 
 * @author river_he@eueang.com
 */
abstract class Kit_Service {
	/**
	 * 模块
	 * 
	 * @var Kit_Model_Abstract[]
	 */
	protected $_mod = array();
	
	/**
	 * constructor
	 */
	public function __construct(){
		$this->init();
	}
	
	/**
	 * 初始化的操作
	 * 
	 * @return void
	 */
	protected function init(){
		$config = include_once('config.php');
		//db config
		Kit_Db_Manager::setConfig($config['database']);
		//memcache config
		Kit_Memcache_Manager::setConfig($config['memcache']);
	}
	
	/**
	 * 获取
	 * 
	 * @return Kit_Memcache
	 */
	protected function getMemcache(){
		return Kit_Memcache_Manager::getMemcache('x01');
	}
	
	/**
	 * 生成缓存的key值
	 * 
	 * @return string
	 */
	protected function getCacheKey($key){
		$keys = get_class($this);
		$keys .= '_'.$key;
		return $keys;
	}
	
	/**
	 * 打包成返回格式数据
	 * 
	 * @param int $code
	 * @param string $message
	 * @param array $return
	 * @return array
	 */
	protected function pack($code, $message, $return=array()){
		$pack = array();
		$pack['code'] = $code;
		$pack['message'] = $message;
		if($return){
			$pack['result'] = $return;
		}
		return $pack;
	}
	
	/**
	 * 获取店主模块
	 * 
	 * @return Kit_Model_Shoper
	 */
	protected function getShoperMod(){
		if(!isset($this->_mod['shoper'])){
			$this->_mod['shoper'] = new Kit_Model_Shoper();
		}
		return $this->_mod['shoper'];
	}
	
	/**
	 * 获取店模块
	 * 
	 * @return Kit_Model_Shop
	 */
	protected function getShopMod(){
		if(!isset($this->_mod['shop'])){
			$this->_mod['shop'] = new Kit_Model_Shop();
		}
		return $this->_mod['shop'];
	}
	
	/**
	 * 获取mode
	 * 
	 * @return Kit_Model_Decorate
	 */
	protected function getDecoMode(){
		if(!isset($this->_mod['deco'])){
			$this->_mod['deco'] = new Kit_Model_Decorate();
		}
		return $this->_mod['deco'];
	}
	

	/**
	 * mode
	 * 
	 * @return Kit_Model_Property
	 */
	protected function getPropMode(){
		if(!isset($this->_mod['prop'])){
			$this->_mod['prop'] = new Kit_Model_Property();
		}
		return $this->_mod['prop'];
	}
	
	/**
	 * 获取任务mod
	 * 
	 * @return Kit_Model_Task
	 */
	protected function getTaskMode(){
		if(!isset($this->_mod['task'])){
			$this->_mod['task'] = new Kit_Model_Task();
		}
		return $this->_mod['task'];
	}
	
	/**
	 * 材料mode
	 * 
	 * @return Kit_Model_Material
	 */
	protected function getMaterMode(){
		if(!isset($this->_mod['mater'])){
			$this->_mod['mater'] = new Kit_Model_Material();
		}
		return $this->_mod['mater'];
	}
	
	/**
	 * npc mode
	 * 
	 * @return Kit_Model_Npc
	 */
	protected function getNpcMode(){
		if(!isset($this->_mod['npc'])){
			$this->_mod['npc'] = new Kit_Model_Npc();
		}
		return $this->_mod['npc'];
	}
	
	/**
	 * 析构
	 */
	public function __destruct(){
		$this->_mod = null;
	}
}
//end